package com.yuyao.myapplication

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

import kotlin.concurrent.Volatile

import android.content.Context;
import android.util.Log
import androidx.compose.ui.text.rememberTextMeasurer


@Database(entities = [Person::class], version = 1,exportSchema = false)
 abstract class PersonDatabase: RoomDatabase() {
    abstract fun personDao(): PersonDao

    companion object {
        @Volatile
        private var INSTANCE: PersonDatabase? = null

        fun getDatabase(context: Context): PersonDatabase {

            try {
                return INSTANCE ?: synchronized(this) {
                    val instance = Room.databaseBuilder(
                        context.applicationContext,
                        PersonDatabase::class.java,
                        "person_database"
                    ).build()
                    INSTANCE = instance
                    instance
                }
            }catch(ex: Exception) {
                Log.e("database",ex.message+"")

              throw ex
            }

        }
    }
}
